00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 if ( !defined("PATH_TO_ROOT") ) {
00026 define( "PATH_TO_ROOT", "../../" );
00027 }
00028
00038 require_once (PATH_TO_ROOT."common/classes/class.format.inc.php");
00039 require_once (PATH_TO_ROOT."roleplay/classes/class.roleartefacts.inc.php");
00040 require_once (PATH_TO_ROOT."teams/classes/class.teamartefacts.inc.php");
00041
00043 require_once (PATH_TO_ROOT."suchmaschine/classes/class.spider.inc.php");
00044
00045 require_once (PATH_TO_ROOT."ressourcen/classes/filemanager/class.folder.inc.php");
00046 require_once (PATH_TO_ROOT."ressourcen/classes/filemanager/class.file.inc.php");
00047
00048 require_once (PATH_TO_ROOT."ressourcen/classes/archiver/class.zipprovider.inc.php");
00049 require_once (PATH_TO_ROOT."ressourcen/classes/archiver/class.archiverexception.inc.php");
00050
00058 class Filemanager {
00059 private $mimeTypes = array();
00060 private $imgFolder;
00061 private $activeFolder;
00062 private $action;
00063 private $actionID;
00064 private $visibleFiles;
00070 public function Filemanager() {
00071 global $db, $resDB;
00072 $this->imgFolder = PATH_TO_ROOT.'ressourcen/icons/';
00073
00074 $this->mimeTypes = array('ez' => 'application/andrew-inset', 'hqx' => 'application/mac-binhex40', 'cpt' => 'application/mac-compactpro', 'doc' => 'application/msword', 'bin' => 'application/octet-stream', 'dms' => 'application/octet-stream', 'lha' => 'application/octet-stream', 'lzh' => 'application/octet-stream', 'exe' => 'application/octet-stream', 'class' => 'application/octet-stream', 'so' => 'application/octet-stream', 'dll' => 'application/octet-stream', 'oda' => 'application/oda', 'pdf' => 'application/pdf', 'ai' => 'application/postscript', 'eps' => 'application/postscript', 'ps' => 'application/postscript', 'smi' => 'application/smil', 'smil' => 'application/smil', 'mif' => 'application/vnd.mif', 'xls' => 'application/vnd.ms-excel', 'ppt' => 'application/vnd.ms-powerpoint', 'wbxml' => 'application/vnd.wap.wbxml', 'wmlc' => 'application/vnd.wap.wmlc', 'wmlsc' => 'application/vnd.wap.wmlscriptc', 'bcpio' => 'application/x-bcpio', 'vcd' => 'application/x-cdlink', 'pgn' => 'application/x-chess-pgn', 'cpio' => 'application/x-cpio', 'csh' => 'application/x-csh', 'dcr' => 'application/x-director', 'dir' => 'application/x-director', 'dxr' => 'application/x-director', 'dvi' => 'application/x-dvi', 'spl' => 'application/x-futuresplash', 'gtar' => 'application/x-gtar', 'hdf' => 'application/x-hdf', 'js' => 'application/x-javascript', 'skp' => 'application/x-koan', 'skd' => 'application/x-koan', 'skt' => 'application/x-koan', 'skm' => 'application/x-koan', 'latex' => 'application/x-latex', 'nc' => 'application/x-netcdf', 'cdf' => 'application/x-netcdf', 'sh' => 'application/x-sh', 'shar' => 'application/x-shar', 'swf' => 'application/x-shockwave-flash', 'sit' => 'application/x-stuffit', 'sv4cpio' => 'application/x-sv4cpio', 'sv4crc' => 'application/x-sv4crc', 'tar' => 'application/x-tar', 'tcl' => 'application/x-tcl', 'tex' => 'application/x-tex', 'texinfo' => 'application/x-texinfo', 'texi' => 'application/x-texinfo', 't' => 'application/x-troff', 'tr' => 'application/x-troff', 'roff' => 'application/x-troff', 'man' => 'application/x-troff-man', 'me' => 'application/x-troff-me', 'ms' => 'application/x-troff-ms', 'ustar' => 'application/x-ustar', 'src' => 'application/x-wais-source', 'xhtml' => 'application/xhtml+xml', 'xht' => 'application/xhtml+xml', 'zip' => 'application/zip', 'au' => 'audio/basic', 'snd' => 'audio/basic', 'mid' => 'audio/midi', 'midi' => 'audio/midi', 'kar' => 'audio/midi', 'mpga' => 'audio/mpeg', 'mp2' => 'audio/mpeg', 'mp3' => 'audio/mpeg', 'aif' => 'audio/x-aiff', 'aiff' => 'audio/x-aiff', 'aifc' => 'audio/x-aiff', 'm3u' => 'audio/x-mpegurl', 'ram' => 'audio/x-pn-realaudio', 'rm' => 'audio/x-pn-realaudio', 'rpm' => 'audio/x-pn-realaudio-plugin', 'ra' => 'audio/x-realaudio', 'wav' => 'audio/x-wav', 'pdb' => 'chemical/x-pdb', 'xyz' => 'chemical/x-xyz', 'bmp' => 'image/bmp', 'gif' => 'image/gif', 'ief' => 'image/ief', 'jpeg' => 'image/jpeg', 'jpg' => 'image/jpeg', 'jpe' => 'image/jpeg', 'png' => 'image/png', 'tiff' => 'image/tiff', 'tif' => 'image/tiff', 'djvu' => 'image/vnd.djvu', 'djv' => 'image/vnd.djvu', 'wbmp' => 'image/vnd.wap.wbmp', 'ras' => 'image/x-cmu-raster', 'pnm' => 'image/x-portable-anymap', 'pbm' => 'image/x-portable-bitmap', 'pgm' => 'image/x-portable-graymap', 'ppm' => 'image/x-portable-pixmap', 'rgb' => 'image/x-rgb', 'xbm' => 'image/x-xbitmap', 'xpm' => 'image/x-xpixmap', 'xwd' => 'image/x-xwindowdump', 'igs' => 'model/iges', 'iges' => 'model/iges', 'msh' => 'model/mesh', 'mesh' => 'model/mesh', 'silo' => 'model/mesh', 'wrl' => 'model/vrml', 'vrml' => 'model/vrml', 'css' => 'text/css', 'html' => 'text/html', 'htm' => 'text/html', 'asc' => 'text/plain', 'txt' => 'text/plain', 'rtx' => 'text/richtext', 'rtf' => 'text/rtf', 'sgml' => 'text/sgml', 'sgm' => 'text/sgml', 'tsv' => 'text/tab-separated-values', 'wml' => 'text/vnd.wap.wml', 'wmls' => 'text/vnd.wap.wmlscript', 'etx' => 'text/x-setext', 'xsl' => 'text/xml', 'xml' => 'text/xml', 'mpeg' => 'video/mpeg', 'mpg' => 'video/mpeg', 'mpe' => 'video/mpeg', 'qt' => 'video/quicktime', 'mov' => 'video/quicktime', 'mxu' => 'video/vnd.mpegurl', 'avi' => 'video/x-msvideo', 'movie' => 'video/x-sgi-movie', 'ice' => 'x-conference/x-cooltalk',);
00075 $this->activeFolder = isset($_GET['activeFolder']) ? $_GET['activeFolder'] : 0;
00076 $this->action = isset($_GET['action']) ? $_GET['action'] : '';
00077 $this->actionID = isset($_GET['actionID']) ? $_GET['actionID'] : 0;
00078 $this->visibleFiles = $db->get_col("SELECT fileID FROM filevisible WHERE userID='".$_SESSION["userid"]."'");
00079 $resDB = new RessourcenDB( $this );
00080 }
00081
00082 public function getActiveFolder() {
00083 return $this->activeFolder;
00084 }
00085
00086 public function getAction() {
00087 return $this->action;
00088 }
00089
00090 public function getActionID() {
00091 return $this->actionID;
00092 }
00093
00094 public function getImgFolder() {
00095 return $this->imgFolder;
00096 }
00097
00103 function showTree() {
00104 global $db;
00105 $template = new Template( PATH_TO_ROOT . "/ressourcen/templates/foldertree.html" );
00106 $tree_entries = "";
00107
00108
00109
00110 $course = $_SESSION['course'];
00111
00112 $plus = 8;
00113 $minus = 6;
00114 $join = 3;
00115 $bottom = false;
00116
00117 $last20 = new Folder(-2);
00118 $last20->setLink("Last 20");
00119 $last20->setName("Die 20 neuesten Dateien dieses Kurses.");
00120 $last20->setFolderType(13);
00121 $last20->setLayerType(5);
00122 $tree_entries .= $last20->drawFolder("", false);
00123
00124 $last20 = new Folder(-1);
00125 $last20->setLink("Top 20");
00126 $last20->setName("Die 20 beliebtesten Dateien dieses Kurses.");
00127 $last20->setFolderType(12);
00128 $last20->setLayerType(5);
00129 $tree_entries .= $last20->drawFolder("", false);
00130
00131 $mainFolder = new Folder();
00132 $mainFolder->setFileManager( $this );
00133 if ($Return = $mainFolder->printSubFolder()) {
00134 $tree_entries .= $Return;
00135 } else {
00136 $tree_entries .= "<span class='tableCell'>Noch keine Ordner angelegt.</span>";
00137 }
00138 eval ( $template->getTemplate() );
00139 }
00140
00141 function showFiles( $statisticView = false ) {
00142 global $resDB;
00143 if ( $this->activeFolder > 0 ) {
00144 $folder = $resDB->getFolderByID( $this->activeFolder );
00145 if (!$folder || !$this->canSeeFile($this->activeFolder))
00146
00147 {
00148 return "Keine solche Ressource verfügbar!";
00149 }
00150 } else {
00151 if ($this->activeFolder == -1) {
00152 $folder = new Folder(-1);
00153 $folder->setFileManager( $this );
00154 $folder->setLink("Top 20");
00155 }
00156 if ($this->activeFolder == -2) {
00157 $folder = new Folder(-2);
00158 $folder->setFileManager( $this );
00159 $folder->setLink("20 neuesten Ressourcen");
00160 }
00161 }
00162
00163 $folder->showFiles( $statisticView );
00164 }
00165
00176 function runAction($file, $COLS, $action = "", $actionID = "", $activeFolder = "") {
00177 global $db;
00178 if (empty($activeFolder)) $activeFolder = $_GET['activeFolder'];
00179 if (empty($action)) $action = isset($_GET['action']) ? $_GET['action'] : '';
00180 if (empty($actionID)) $actionID = isset($_GET['actionID']) ? $_GET['actionID'] : '';
00181 if (!$action || (is_object($file) && $file->fileID != $actionID) || (!is_object($file) && $file != $actionID)) return false;
00182 switch ($action) {
00183 case 'delete_trueFile':
00184 if ($_SESSION['userid'] == $file->userID || $_SESSION['usergroup'] == ADMIN || ($_SESSION["usergroup"] == DOZENT && $_SESSION["course"] > 0)) {
00185 if ($file->type == 'file') {
00186 $this->deleteFile($file->link);
00187
00188 $spider = new Spider();
00189 $spider->start("remove-file", $file->fileID);
00190 }
00191 $db->query("DELETE FROM filelist WHERE fileID='$file->fileID'");
00192 $db->query("DELETE FROM filelog WHERE fileID='$file->fileID'");
00193 $db->query("DELETE FROM filevisible WHERE fileID='$file->fileID'");
00194 RoleArtefacts::deleteItem(RESSOURCE, (int)$file->fileID);
00195 TeamArtefacts::deleteItem(RESSOURCE, (int)$file->fileID);
00196 } else {
00197 return "Zugriff verweigert!";
00198 }
00199 break;
00200
00201 case 'delete_trueFolder':
00202 if ($_SESSION['usergroup'] == ADMIN || ($_SESSION["usergroup"] == DOZENT && $_SESSION["course"] > 0)) {
00203 $this->deleteFolder($activeFolder);
00204 unset($_GET['activeFolder']);
00205 } else {
00206 return "Zugriff verweigert!";
00207 }
00208 break;
00209
00210
00211 case 'editFolder':
00212 break;
00213
00214 case 'studentWriteFolder':
00215 if ($_SESSION['usergroup'] != 2) {
00216 $writeState = $db->get_var("SELECT student_write FROM filelist WHERE fileID='$actionID' ");
00217 $writeState = ($writeState == 1 ? 0 : 1);
00218 $db->query("UPDATE filelist SET student_write='$writeState' WHERE fileID='$actionID'");
00219 } else {
00220 echo "<tr><td class='res_file-extra' colspan='".$COLS."'>Zugriff verweigert!</td>";
00221 }
00222 break;
00223
00224 case 'setVisibilityDocentsOnly':
00225 if (isset($_GET['mode'])) $this->setRessourceVisibility($actionID, 3, $_GET['mode']);
00226 else $this->setRessourceVisibility($actionID, 3, 1);
00227 header('Location: filemanager.php?activeFolder='.$activeFolder);
00228 break;
00229
00230 case 'setVisibilityNoStudents':
00231 if (isset($_GET['mode'])) $this->setRessourceVisibility($actionID, 2, $_GET['mode']);
00232 else $this->setRessourceVisibility($actionID, 2, 1);
00233 header('Location: filemanager.php?activeFolder='.$activeFolder);
00234 break;
00235
00236 case 'setVisibilityAll':
00237 if (isset($_GET['mode'])) $this->setRessourceVisibility($actionID, 1, $_GET['mode']);
00238 else $this->setRessourceVisibility($actionID, 1, 1);
00239 header('Location: filemanager.php?activeFolder='.$activeFolder);
00240 break;
00241 }
00242 }
00243
00251 function deleteFolder($folderID) {
00252 global $db, $EZSQL_ERROR;
00253 $folders = $db->get_results("SELECT type, fileID, link FROM filelist WHERE parent_object='$folderID'");
00254 if ($folders) {
00255 foreach($folders as $folder) {
00256 if ($folder->type == "file") {
00257 $this->deleteFile($folder->link);
00258
00259 $spider = new Spider();
00260 $spider->start("remove-file", $folder->fileID);
00261 }
00262 $this->deleteFolder($folder->fileID);
00263 }
00264 }
00265 $errorCount = count($EZSQL_ERROR);
00266 $db->query("DELETE FROM filelist WHERE fileID='$folderID'");
00267 $db->query("DELETE FROM filelog WHERE fileID='$folderID'");
00268 $db->query("DELETE FROM filetreelayout WHERE folderID='$folderID'");
00269 $db->query("DELETE FROM filevisible WHERE fileID='$folderID'");
00270 RoleArtefacts::deleteItem(RESSOURCE, (int)$folderID);
00271 TeamArtefacts::deleteItem(RESSOURCE, (int)$folderID);
00272 if (count($EZSQL_ERROR) > $errorCount) return false;
00273 return true;
00274 }
00282 function deleteFile($file) {
00283 global $settings;
00284 $basedir = PATH_TO_ROOT.$settings["upload_path"].'filemanager/courseID/'.$_SESSION['course'];
00285 if (!file_exists($basedir."/".$file)) return false;
00286 if (!unlink($basedir."/".$file)) return false;
00287 return true;
00288 }
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300 private function setRessourceVisibility($ressourceID, $visibilityToSet, $contentRecursive) {
00301 global $db, $EZSQL_ERROR;
00302
00303 $visible = $db->get_var("SELECT visible_type FROM filelist WHERE fileID='$ressourceID'");
00304
00305 if ($visible == $visibilityToSet && $contentRecursive == 1) return true;
00306
00307
00308 if ($contentRecursive > 1) {
00309 $ressources = $db->get_results("SELECT type, fileID, link , visible_type FROM filelist WHERE parent_object='$ressourceID'");
00310 if ($ressources != null) {
00311
00312
00313 foreach($ressources as $ressource) {
00314
00315 if ($ressource->type == "file") {
00316 $this->setRessourceVisibility($ressource->link, $visibilityToSet, $contentRecursive);
00317 }
00318
00319 if ($contentRecursive == 2) $this->setRessourceVisibility($ressource->fileID, $visibilityToSet, 4);
00320 else $this->setRessourceVisibility($ressource->fileID, $visibilityToSet, $contentRecursive);
00321 }
00322 }
00323 }
00324
00325 if ($contentRecursive != 2) {
00326
00327 $errorCount = count($EZSQL_ERROR);
00328 $db->query("UPDATE filelist SET visible_type ='$visibilityToSet' WHERE fileID='$ressourceID'");
00329 $visible = $db->get_var("SELECT visible_type FROM filelist WHERE fileID='$ressourceID'");
00330 if (count($EZSQL_ERROR) > $errorCount) return false;
00331 if ($contentRecursive > 2) {
00332 $db->query("DELETE FROM filevisible WHERE fileID='".$ressourceID."'");
00333 }
00334 }
00335 return true;
00336 }
00346 function createLink($oldOnes = true, $vars = '', $link = '') {
00347 if ($link == "") $link = PATH_TO_ROOT.SCRIPT_NAME;
00348 if (!is_array($vars)) $vars = $_GET;
00349 elseif (count($_GET) > 0 && $oldOnes) $vars = array_merge($_GET, $vars);
00350 foreach($vars as $getVarName => $getVarValue) {
00351 if (trim($getVarValue) != "" && isset($getVarValue)) $getVars[] = urlencode($getVarName) ."=".urlencode($getVarValue);
00352 }
00353 return $link."?".implode($getVars, "&");
00354 }
00362 function downloadFile($fileID) {
00363 global $settings, $db;
00364
00365 $file = $db->get_row("SELECT name, link, size, extension, orig_filename, courseID FROM filelist WHERE fileID='".$fileID."'");
00366 if (!$this->canSeeFile($fileID)) {
00367 return "Sie haben keine Berechtigung diese Datei herunterzuladen!";
00368 }
00369
00370 $basedir = PATH_TO_ROOT.$settings["upload_path"].'filemanager/courseID/'.$file->courseID;
00371
00372 $filename = sprintf("%s/%s", $basedir, $file->link);
00373 if (!file_exists($filename)) return "Datei nicht vorhanden, bitte wenden Sie sich an den Administrator!";
00374
00375 if (isset($this->mimeTypes[$file->extension])) {
00376 $mimetype = $this->mimeTypes[$file->extension];
00377 } else {
00378 $mimetype = "application/octet-stream";
00379 }
00380
00381 $time = time();
00382 $db->query("INSERT INTO filelog (userID, fileID, date) VALUES ('".$_SESSION['userid']."','$fileID','$time')");
00383 $db->query("UPDATE filelist SET counter=counter+1 WHERE fileID='$fileID'");
00384
00385 ob_end_clean();
00386
00387 header("Pragma: private");
00388 header("Cache-control: private, must-revalidate");
00389 header("Content-Type: $mimetype");
00390 header("Content-Disposition: attachment; filename=\"".$file->orig_filename."\"");
00391 header("Content-Transfer-Encoding: binary");
00392 header("Content-Length: ".$file->size);
00393
00394 readfile($filename);
00395 return "";
00396 }
00404 function openLink($fileID) {
00405 global $db;
00406 if (!$this->canSeeFile($fileID)) {
00407 return "Sie haben keine Berechtigung diesen Link zu öffnen!";
00408 }
00409
00410 $link = $db->get_var("SELECT link FROM filelist WHERE fileID='".$fileID."'");
00411
00412 $time = time();
00413 $db->query("INSERT INTO filelog (userID, fileID, date) VALUES ('".$_SESSION['userid']."','$fileID','$time')");
00414 $db->query("UPDATE filelist SET counter=counter+1 WHERE fileID='$fileID'");
00415 if (Utilities::validateURL($link)) header("Location: ".$link);
00416 exit();
00417 }
00427 function replaceSpecialChars($string, $special) {
00428 $strlen = strlen($special);
00429 for ($i = 0 ; $i <= $strlen ; $i++) {
00430 $char = substr($special, $i, 1);
00431 $string = str_replace($char, "_", $string);
00432 $string = str_replace("__", "_", $string);
00433 }
00434 $string = str_replace("__", "_", $string);
00435 return $string;
00436 }
00444 function canSeeFile($fileID) {
00445
00446
00447
00448
00449
00450
00451
00452 global $db;
00453
00454 if ($_SESSION['usergroup'] == ADMIN || $_SESSION['usergroup'] == DOZENT) return true;
00455 $file = $db->get_row("SELECT courseID, userID, visible_type, parent_object FROM filelist WHERE fileID='$fileID'");
00456
00457 if (!isset($file)) return false;
00458
00459 if (is_null($file) || $_SESSION['course'] != $file->courseID && $file->courseID != 0) return false;
00460
00461 if ($file->visible_type == 1) {
00462
00463 $parentID = $file->parent_object;
00464 while ($parentID != 0) {
00465 $parentFolder = $db->get_row("SELECT visible_type, parent_object FROM filelist WHERE fileID='$parentID'");
00466 if ($parentFolder->visible_type > 1) return false;
00467 $parentID = $parentFolder->parent_object;
00468 }
00469 return true;
00470 }
00471
00472 if (isset($_SESSION['assistent']) && $file->visible_type == 2) {
00473
00474 $parentID = $file->parent_object;
00475 while ($parentID != 0) {
00476 $parentFolder = $db->get_row("SELECT visible_type, parent_object FROM filelist WHERE fileID='$parentID'");
00477 if ($parentFolder->visible_type == 3) return false;
00478 $parentID = $parentFolder->parent_object;
00479 }
00480 return true;
00481 }
00482
00483 if ($_SESSION['userid'] == $file->userID) return true;
00484
00485 if ($db->get_var("SELECT count(*) FROM filevisible WHERE fileID='$fileID' AND userID='".$_SESSION['userid']."'") > 0) return true;
00486 return false;
00487 }
00488
00499 public function getArchivedFolder($folderID, $recursion = FALSE) {
00500 global $resDB;
00501 global $settings;
00502
00503 if ($folderID > 0) {
00504 $folder = $resDB->getFolderByID($folderID);
00505
00506 if (!$folder instanceof Folder) {
00507 return "Ordner mit der ID ".$folderID." wurde nicht gefunden.";
00508 }
00509 } elseif ($folderID == -2) {
00510 $folder = new Folder(-2);
00511 $folder->setLink("Last 20");
00512 $folder->setCourseID($_SESSION['course']);
00513 $folder->setDescription("Die 20 neuesten Dateien dieses Kurses.");
00514 } elseif ($folderID == -1) {
00515 $folder = new Folder(-1);
00516 $folder->setLink("Top 20");
00517 $folder->setCourseID($_SESSION['course']);
00518 $folder->setDescription("Die 20 beliebtesten Dateien dieses Kurses.");
00519 } else {
00520 return "Ordner mit der ID ".$folderID." wurde nicht gefunden.";
00521 }
00522
00523 try {
00524 if (ZipProvider::checkArchiveSize($folder, $recursion) <=
00525 $settings['filemanager_archive_max_filesize']*1024*1024) {
00526
00527 $zipProvider = new ZipProvider($folder, $recursion);
00528 $zipProvider->createArchive();
00529 $zipProvider->sendArchive();
00530 }
00531 } catch (ArchiverException $e) {
00532 return $e->getMessage();
00533 }
00534
00535 return "";
00536 }
00537 }
00538 ?>